/*
 * DelayBlock.cpp
 *
 *  Created on: 25.04.2013
 *      Author: Lapchinskiy
 */
#include "BuildConfig.h"
#include "Global_types.h"
#include "Block.h"
#include "ArrayList.h"
#include "Condition.h"
#include "ConditionBlock.h"
#include "Task.h"
#include "TimeManager.h"
#include "CommandHandler.h"
#include "Scheduler.h"
#include "DelayBlock.h"

DelayBlock::DelayBlock(uint32_t delayTime) :
    errorCode(NO_ERR)
  {

    this->nextBlock = this;
    this->delayTime = delayTime;
    timeToExit = 0; //
    firstStep = true;
  }

ErrorCode DelayBlock::setNexBlock(Block* nextBlock)
  {
    this->nextBlock = nextBlock;
    return errorCode;
  }

Block* DelayBlock::step(void)
  {
    if (firstStep)
      {
        firstStep = false;
        timeToExit = *TimeManager::GetSystemTime() + delayTime;
      }
    else
      {
        if ((*TimeManager::GetSystemTime()) >= timeToExit)
          {
            firstStep = true;
            return nextBlock;
          }
      }
    return this;
  }

DelayBlock::~DelayBlock()
  {
    // TODO Auto-generated destructor stub
  }

